package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.shopping.domain.MallCommissionBalance;
import com.ruoyi.shopping.service.IMallCommissionBalanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 佣金余额Controller
 *
 * @author scx
 * @date 2022-06-10
 */
@RestController
@RequestMapping("/shopping/commissionBalance")
public class MallCommissionBalanceController extends BaseController
{
    @Autowired
    private IMallCommissionBalanceService mallCommissionBalanceService;

    /**
     * 查询佣金余额列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCommissionBalance mallCommissionBalance)
    {
        startPage();
        List<MallCommissionBalance> list = mallCommissionBalanceService.selectMallCommissionBalanceList(mallCommissionBalance);
        return getDataTable(list);
    }

    /**
     * 导出佣金余额列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:export')")
    @Log(title = "佣金余额", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallCommissionBalance mallCommissionBalance)
    {
        List<MallCommissionBalance> list = mallCommissionBalanceService.selectMallCommissionBalanceList(mallCommissionBalance);
        ExcelUtil<MallCommissionBalance> util = new ExcelUtil<MallCommissionBalance>(MallCommissionBalance.class);
        return util.exportExcel(list, "佣金余额数据");
    }

    /**
     * 获取佣金余额详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallCommissionBalanceService.selectMallCommissionBalanceById(id));
    }

    /**
     * 新增佣金余额
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:add')")
    @Log(title = "佣金余额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCommissionBalance mallCommissionBalance)
    {
        return toAjax(mallCommissionBalanceService.insertMallCommissionBalance(mallCommissionBalance));
    }

    /**
     * 修改佣金余额
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:edit')")
    @Log(title = "佣金余额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCommissionBalance mallCommissionBalance)
    {
        mallCommissionBalance.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(mallCommissionBalanceService.updateMallCommissionBalance(mallCommissionBalance));
    }

    /**
     * 删除佣金余额
     */
    @PreAuthorize("@ss.hasPermi('shopping:commissionBalance:remove')")
    @Log(title = "佣金余额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallCommissionBalanceService.logicDeleteMallCommissionBalance(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
